Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ActiveRecord translations support #35

Closed
wants to merge 3 commits into from

Conversation

hrom512
Copy link

@hrom512 hrom512 commented Oct 13, 2016

Fix problem with translations for ActiveRecord attributes. For example:

class Song < ActiveRecord::Base
end

class SongForm < Reform::Form
  include Reform::Form::ActiveModel::Validations
  include Reform::Form::ActiveRecord

  property :title
end

# returns "Title" despite I18n translations
SongForm.human_attribute_name(:title)

@apotonick
Copy link
Member

That's cool! However, it will be a breaking API change.

@zavan
Copy link

zavan commented Jun 22, 2017

This can be closed, since human_attribute_name is now delegated to the model class (but there's a problem if you're using trailblazer-rails: trailblazer/trailblazer-rails#47)

@ValentinTrinque
Copy link

Where are we on this ? I encounter this very problem. How can we get this fixed ? I am wiling to help if needed.

oliverguenther added a commit to opf/openproject that referenced this pull request Jan 8, 2018
The validator passed to AM::Error does not use the `i18n_scope` we
define on either Reform::Form or the model, but is delegated from the
included AM::Translations module.

This in turn causes I18n to lookup the scope `:activemodel`, failing the
localization.

trailblazer/reform-rails#56
trailblazer/reform-rails#35
@oliverguenther
Copy link

This still occurs even if your model or form defines i18n_scope due to the fact the the validator delegates to AM::Naming (https://github.com/trailblazer/reform-rails/blob/master/lib/reform/form/active_model/validations.rb#L141).

Since we depend upon for accessing AR keys, opening the validator class to enforce the scope works - while not pretty - as expected:

Reform::Form::ActiveModel::Validations::Validator.class_eval do
  ##
  # use activerecord as the base scope instead of 'activemodel' to be compatible
  # to the messages we have already stored
  def self.i18n_scope
    :activerecord
  end
end

What is needed to move this PR forward?

@apotonick
Copy link
Member

The main problem is that this fix will break a lot of code since we "force" the correct i18n key. There should be a soft deprecation so we can undo this.

@apotonick
Copy link
Member

apotonick commented Jan 8, 2018

Maybe an explicit require "reform/active_record/i18n" or something?

oliverguenther added a commit to opf/openproject that referenced this pull request Jan 9, 2018
The validator passed to AM::Error does not use the `i18n_scope` we
define on either Reform::Form or the model, but is delegated from the
included AM::Translations module.

This in turn causes I18n to lookup the scope `:activemodel`, failing the
localization.

trailblazer/reform-rails#56
trailblazer/reform-rails#35

[ci skip]
@emaglio
Copy link
Member

emaglio commented Sep 22, 2019

Really old PR which I'll close for now @hrom512, if you still using reform-rails could you please test master branch

@emaglio emaglio closed this Sep 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants